<!DOCTYPE html>
<html>
	<head> 
		<meta charset="UTF-8" />
		<title>修改 用户</title>
		<link rel="stylesheet" th:href="@{/moon/css/bootstrap2.css}" />
		<link rel="stylesheet" th:href="@{/menu/metisMenu.css}" />
	</head> 
	 
	<body class="bg-pm">
		
		<div class="container-fluid" style="overflow: hidden;" id="app">
		
			<center><h2 style="margin-top:10px" class="mb-5">修改用户</h2></center>
	
			<form class="form-horizontal" onsubmit="return updateUser()">
  				
  				<div class="form-group" >
			    	<label for="uName" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">账户名</label>
			    	<div class="col-sm-5" style="display:inline-block">
			      		<input type="text" class="form-control" id="uName" name="uName" placeholder="请输入账户名" 
			      		       required onblur="checkNameExists(this.value)" maxlength=50 th:value=${adminuser.uname}>
			    	</div>
			    	<div class="col-sm-5" style="display:inline-block" ><span id="unametips" ></span></div>
			  	</div> 
			  	
				<div class="form-group">
			    	<label for="uEmail" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">邮箱</label>
			    	<div class="col-sm-5" style="display:inline-block">
			      		<input type="text" class="form-control" id="uEmail" name="uEmail" placeholder="请输合法邮箱" 
			      			   onblur="checkEmail(this.value)" th:value=${adminuser.email}>
			    	</div>
			    	<div class="col-sm-5" style="display:inline-block" ><span id="uemailtips" ></span></div>
			  	</div>
				
				<div class="form-group">
			    	<label for="uPhone" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">手机号</label>
			    	<div class="col-sm-5" style="display:inline-block">
			      		<input type="text" class="form-control" id="uPhone" name="uPhone" placeholder="请输入手机号" 
				      		   onblur="checkPhoneNumber(this.value)" th:value="${adminuser.tel}">
			    	</div>
			    	<div class="col-sm-5" style="display:inline-block" ><span id="uphonetips" ></span></div>
			  	</div>
				
				
				<div class="form-group">
			    	<label for="uLoginPass" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">登录密码</label>
			    	<div class="col-sm-5" style="display:inline-block" >
			      		<input type="password" class="form-control" id="uLoginPass" name="uLoginPass" placeholder="请输入6-12位数字、字母密码" 
			      			   required onblur="checkLoginPass(this.value)" maxlength=12 th:value="${adminuser.upass}">
			    	</div>
			    	<div class="col-sm-5" style="display:inline-block" ><span id="uloginpasstips" ></span></div>
			  	</div>
			  	
			  	<div class="form-group">
			    	<label for="uBuyPass" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">支付密码</label>
			    	<div class="col-sm-5" style="display:inline-block" >
			      		<input type="password" class="form-control" id="uBuyPass" name="uBuyPass" placeholder="请输入6-12位数字、字母密码" 
			      			   required onblur="checkBuyPass(this.value)" maxlength=12 th:value="${adminuser.accountpassword}">
			    	</div>
			    	<div class="col-sm-5" style="display:inline-block" ><span id="ubuypasstips" ></span></div>
			  	</div>
			  	
			  	
			  	<div class="form-group">
			    	<label for="uIdCard" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">身份证号</label>
			    	<div class="col-sm-5" style="display:inline-block">
			      		<input type="text" class="form-control" id="uIdCard" name="uIdCard" placeholder="请输入身份证号" 
			      		       onblur="checkidcard(this.value)" th:value="${adminuser.idcard}">
			    	</div>
			    	<div class="col-sm-5" style="display:inline-block" ><span id="uidcardtips" ></span></div>
			  	</div>
			  	
			  	<div class="form-group">
					<label for="userStatus" class="col-sm-1 control-label"  style="display:inline-block; padding-rigrt:5px">用户状态</label>
  					<div class="col-sm-5" style="display:inline-block" >
  						<select class="form-control" id="userStatus" >
    						<option value="正常" >正常</option>
    						<option value="禁止出价" >禁止出价</option>
    						<option value="禁止评论" >禁止评论</option>
    						<option value="禁言" >禁言</option>
  						</select>
  					</div>
			  	</div>
			  	
			  	<div class="form-group">
					<label for="accountStatus" class="col-sm-1 control-label" style="display:inline-block; padding-rigrt:5px">账户状态</label>
					<div class="col-sm-5" style="display:inline-block" >
	  					<select class="form-control" id="accountStatus" >
	    					<option value="待激活">待激活</option>
	    					<option value="正常">正常</option>
	    					<option value="禁止登录" >禁止登录</option>
	    					<option value="已注销">已注销</option>
	  					</select>
	  				</div>
			  	</div>
			  	
			  	
			  	<div class="form-group">
    				<div class="col-sm-offset-2 col-sm-10">
      					 <input type="button" class="btn btn-bg btn-info" onclick="reload();" value="取消">
      					<input type="submit" class="btn btn-bg btn-info" value="提交" style="margin-left:10px">
					</div>
  				</div>
			</form>
			
			<script th:src="@{/moon/js/jquery.js}"></script>
			<script th:src="@{/moon/js/vue.js}"></script>
			<script th:src="@{/layer/layer.js}"></script>
			<script th:src="@{/page/jqpaginator.js}"></script>
			<script th:inline="javascript">
			
			//下拉框回显
			$(function(){
				$('#userStatus').val([[${adminuser.userstatus}]]);
				$('#accountStatus').val([[${adminuser.accountstatus}]]);
			})
			
			var oldname=[[${adminuser.uname}]];
			
			//-- 利用ajax异步请求，验证用户名是否可用
			//-- 一般在进行验证前，利用一些手段如正则表达式初步验证用户名的合法性
			function checkNameExists(uName){
				$.post(
						"/auction/User/selectUserByName",
						{ uName:$('#uName').val() },
						function (data) {
							if ((data == "false") || ($('#uName').val() == oldname)) { 
					    		document.getElementById("unametips").innerHTML = "用户名可用";
							}else{
								document.getElementById("unametips").innerHTML = "用户名不可用";
							}
						}
					);
			}
			
			
			//正则判断登录密码是否合法
			function checkLoginPass(uLoginPass){
				var myreg = /^[a-zA-Z0-9]{6,12}$/;
			      if (!myreg.test(uLoginPass)) {  
			    	  document.getElementById("uloginpasstips").innerHTML = "密码由6-12位数字、字母自由组成";
			      } else {  
			    	  document.getElementById("uloginpasstips").innerHTML = "登录密码";
			      } 
				
			}
			
			//正则判断支付密码是否合法
			function checkBuyPass(uBuyPass){
				var myreg = /^[a-zA-Z0-9]{6,12}$/;
			      if (!myreg.test(uBuyPass)) {  
			    	  document.getElementById("ubuypasstips").innerHTML = "密码由6-12位数字、字母自由组成";
			      } else {  
			    	  document.getElementById("ubuypasstips").innerHTML = "支付密码";
			      } 
				
			}
			
			//正则判断邮箱是否合法
			function checkEmail(uEmail){
				var myreg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
			      if (!myreg.test(uEmail)) {  
			    	  document.getElementById("uemailtips").innerHTML = "请输入合法邮箱";
			      } else {  
			    	  document.getElementById("uemailtips").innerHTML = "邮箱";
			      } 
				
			}
			

			//正则判断手机号是否合法
			function checkPhoneNumber(uPhone){
				var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
			      if (!myreg.test(uPhone)) {  
			    	  document.getElementById("uphonetips").innerHTML = "请输入合法合法手机号";
			      } else {  
			    	  document.getElementById("uphonetips").innerHTML = "手机号";
			      } 
				
			}
			

			//正则判断身份证号是否合法
			function checkidcard(uIdCard){
				var myreg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
			      if (!myreg.test(uIdCard)) {  
			    	  document.getElementById("uidcardtips").innerHTML = "请输入合法合法身份证号";
			      } else {  
			    	  document.getElementById("uidcardtips").innerHTML = "身份证号";
			      } 
				
			}
			
			
			function reload(){
				location.href="/auction/Admin/adminiframe/selectAdminByCond";
			}

			//-- 不执行表单的submit的跳转，同时保留requirded的特性
			//-- 属性全部搞出来，为例后面的更新
			function updateUser(){

				//下拉框回显
				$(function(){
					$('#userStatus').val([[${adminuser.userstatus}]]);
					$('#accountStatus').val([[${adminuser.accountstatus}]]);
				})
				
				
				$.post(
					"/auction/User/updateUser",{
						uId:[[${adminuser.uid}]],//从model域取key值对象的属性
						uName : $('#uName').val(),
						uLoginPass : $('#uLoginPass').val(),
						uBuyPass : $('#uBuyPass').val(),
						uEmail: $('#uEmail').val(),
						uPhone: $('#uPhone').val(),
						uIdCard: $('#uIdCard').val(),
						userStatus: $('#userStatus').val(),
						accountStatus: $('#accountStatus').val()
					},
					function (data) {
						if(data=="true"){
							alert("修改成功");
							location.href="/auction/Admin/adminiframe/selectUserByCond";
						}
						else{
							layer.alert("修改失败");
							location.href="/auction/User/goUpdateUser?aId="+[[${adminuser.uid}]];	
						}
					}
				); 
				
				return false;
			}

			</script>
		</div>
	</body>
</html>